package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.app.DownLoadUserReviewDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserReviewDataCommand;
import com.cskaoyan.wordmemorize.service.UserReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/review")
public class UserReviewController {
    
    
    
    @Autowired
    UserReviewService userReviewService;
    
    // 添加用户的单词复习数据
    @PostMapping("voc")
    public Result addUserVocRev(@RequestBody List<Long> vocIds) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        
        userReviewService.addUserRovRev(vocIds, userId);
        
        return Result.ok("添加单词复习数据成功！");
    }

    /**
     * 下载用户的复习数据
     * @param pageRequest
     * @return
     */
    @GetMapping("data")
    public Result<DownLoadUserReviewDTO> loadUserRev(PageRequest pageRequest) {
        Long userId = StpKit.USER.getLoginIdAsLong();

        DownLoadUserReviewDTO downLoadUserReviewDTO = userReviewService.downloadUserReviewData(pageRequest, userId);
        
        return Result.ok(downLoadUserReviewDTO);
    }

    /**
     * 同步用户的复习数据
     * @param userReviewDataCommand
     * @return
     */
    @PostMapping("data")
    public Result synchronizeUserReviewData(@RequestBody UserReviewDataCommand userReviewDataCommand) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        
        userReviewService.synchronizeUserReviewData(userReviewDataCommand, userId);
        
        return Result.ok("同步成功！");
    }
    
    
}
